package com.wlr.study.leetcode;

public class LeetCode121 {
    public static int maxProfit(int[] prices) {
        int max = 0;
        int min = Integer.MAX_VALUE;
        for (int price : prices) {
            if (min > price) {
                min = price;
            } else if (price - min > max) {
                max = price - min;
            }
        }
        return max;


    }

    public static void main(String[] args) {
        System.out.println(LeetCode121.maxProfit(new int[]{2, 4, 1}));
    }
}
